package com.example.home.bus.activity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.CalendarView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.example.home.R;

public class MakeNext1 extends AppCompatActivity {

    private CalendarView calendarView;
    private TextView selectedDateTextView;
    private Button prevButton;
    private Button nextButton;
    private String selectedDate;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_make_next1);

        // 获取从上一步页面传递过来的数据
        Intent intent = getIntent();
        String start = intent.getStringExtra("start");
        String end = intent.getStringExtra("end");
        String price = intent.getStringExtra("price");
        String path = intent.getStringExtra("path");

        calendarView = findViewById(R.id.calendarView);
        selectedDateTextView = findViewById(R.id.selectedDateTextView);
        prevButton = findViewById(R.id.prevButton);
        nextButton = findViewById(R.id.nextButton);

        prevButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MakeNext1.this.finish();
            }
        });

        // 设置日期更改监听器
        calendarView.setOnDateChangeListener((view, year, month, dayOfMonth) -> {
            // 更新选定的日期文本
            updateSelectedDate(year, month + 1, dayOfMonth);
            // 使“下一步”按钮可见
            nextButton.setVisibility(View.VISIBLE);
        });

        nextButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MakeNext1.this, MakeNext2.class);
                intent.putExtra("start", start);
                intent.putExtra("end", end);
                intent.putExtra("price", price);
                intent.putExtra("path1", path);
                Log.e("xhf",selectedDate);
                intent.putExtra("selectedDate", selectedDate);
                startActivity(intent);
            }
        });
    }

    // 方法用于更新选定的日期文本
    private void updateSelectedDate(int year, int month, int dayOfMonth) {
        selectedDate = String.format("%04d/%02d/%02d", year, month, dayOfMonth);
        selectedDateTextView.setText(selectedDate);

    }


}